package utils

import (
	"server5/Interface"
	"time"
)


//定时器类
type MyTicker struct {
	t        *time.Ticker
	stopExit chan bool
	router   Interface.IRouter
}

func NewMyTicker(d time.Duration) *MyTicker {
	return &MyTicker{
		t:        time.NewTicker(d),
		stopExit: make(chan bool),
	}
}

func (m *MyTicker) Start(work func()) {
	go func() {
		for {
			select {
			case <-m.t.C:
				//TODO work()
			case <-m.stopExit:
				m.t.Stop()
				return
			}
		}
	}()
}

func (m *MyTicker) Stop () {
	m.stopExit <- true
}